﻿using System;   
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using CrystalDecisions.CrystalReports.Engine;
using Wpf2.Models;

namespace Wpf2.Views
{
    /// <summary>
    /// Interaction logic for CrystalReportAddInventory.xaml
    /// </summary>
    public partial class FormCrystalReportAddInventory 
    {
        public FormCrystalReportAddInventory(IEnumerable<Products> listProducts, DateTime orderDate, IDictionary<string, string> param, bool isMarcle)
        {
            InitializeComponent();
            try
            {
                var path = Environment.CurrentDirectory;
                var report = new ReportDocument();
                string link;
                if(isMarcle)
                    link = path.Insert(path.Length, "\\CrystalReport\\CrystalReportMarcleAddInvetory.rpt");
                else
                    link = path.Insert(path.Length, "\\CrystalReport\\CrystalReportAddInvetory.rpt");
                
                report.Load(link);
                
                report.SetDataSource(listProducts.ToList());
                report.SetParameterValue("StoreName", param["StoreName"]);
                report.SetParameterValue("Address", param["Address"]);
                report.SetParameterValue("Phone", param["Phone"]);
                report.SetParameterValue("Mobile", param["Mobile"]);
                
                report.SetParameterValue("OrderDate", orderDate);
                CRViewer.ViewerCore.ReportSource = report;
            }
            catch (Exception e)
            {

                MessageBox.Show(e.Message);
            }
        }
    }
}
